package com.weseal.response;

import com.github.pagehelper.PageInfo;
import com.weseal.query.PageQuery;

import java.io.Serializable;
import java.util.List;

/**
 * @author weseal
 * @title
 * @description
 * @usage
 * @copyright Copyright 2014  rrmj Corporation. All rights reserved.
 * @company 上海众多美网络科技有限公司
 * @create 2017/9/9
 */
public class ResponseResult<T> extends CommonResult implements Serializable {

	private long total = 0;
	private PageQuery query;

	public ResponseResult(String code, String message) {
		super(code, message, null);
	}

	public ResponseResult(List<T> data, PageQuery pageQuery, List originPageInfo) {
		super("200", "", data);
		PageInfo pageInfo = new PageInfo(originPageInfo);
		if (pageInfo != null) {
			this.total = pageInfo.getTotal();
		}
		this.query = pageQuery;
	}

	public static ResponseResult initSuccess() {
		ResponseResult responseResult = new ResponseResult("200", "success");
		return responseResult;
	}

	public Long getTotal() {
		return total;
	}

	public void setTotal(Long total) {
		this.total = total;
	}

	public List<T> getData() {
		return (List<T>) super.getData();
	}

	public PageQuery getQuery() {
		return query;
	}

	public void setQuery(PageQuery query) {
		this.query = query;
	}
}
